package com.mofeng.myshop.controller.admin;


import com.mofeng.myshop.domain.dto.CommodityCategoryDto;
import com.mofeng.myshop.service.ICommodityCategoryService;
import com.mofeng.myshop.until.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品分类 前端控制器
 * </p>
 *
 * @author MoFeng
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/admin/commodity-category")
@RequiredArgsConstructor
@PreAuthorize(value = "@permissionService.ADMIN()")
@Tag(name = "商品分类相关接口", description = "商品分类相关接口")
public class CommodityCategoryAdminController {

    private final ICommodityCategoryService commodityCategoryService;

    @Operation(summary = "添加商品分类")
    @PostMapping("")
    @PreAuthorize(value = "@permissionService.MASTER()")
    public R addCommodity(@RequestBody CommodityCategoryDto commodityDto) {
        return commodityCategoryService.saveCategory(commodityDto);
    }

    @Operation(summary = "删除商品分类")
    @DeleteMapping()
    @PreAuthorize(value = "@permissionService.MASTER()")
    public R delCommodity(@RequestParam("id") List<String> ids) {
        return commodityCategoryService.delCategory(ids);
    }

    @Operation(summary = "修改商品分类")
    @PutMapping("")
    @PreAuthorize(value = "@permissionService.MASTER()")
    public R updateCommodity(@RequestBody CommodityCategoryDto commodityDto) {
        return commodityCategoryService.saveCategory(commodityDto);
    }

    @Operation(summary = "获取商品分类列表")
    @GetMapping("/list")
    public R getCommodityList(@RequestParam(value = "projectId", required = false) String projectId) {
        return commodityCategoryService.getCategoryList(projectId);
    }

}
